﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using JigLibX.Collision;
using JigLibX.Physics;
using JigLibX.Geometry;
using JigLibX.Math;
using DARE;

namespace DARE
{
    public class APhysicController : Controller
    {

    #region fields

        protected Body m_body;
        protected Vector3 m_force = Vector3.Zero;
        protected Vector3 m_torque = Vector3.Zero;

    #endregion

    #region ctor

        public APhysicController()
        {
            Initialize(null);
        }

        public APhysicController(Body body)
        {
            Initialize(body);
        }

        public void Initialize(Body body)
        {
            EnableController();
            m_body = body;
        }

    #endregion

    #region properties

        public Body Body
        {
            get { return m_body; }
        }

        public Vector3 Force
        {
            get { return m_force; }
            set { m_force = value; }
        }

        public Vector3 Torque
        {
            get { return m_torque; }
            set { m_torque = value; }
        }

    #endregion

    #region methods

        public override void UpdateController(float dt)
        {
            if (m_body == null)
                return;
            if (m_force != null && m_force != Vector3.Zero)
            {
                m_body.AddBodyForce(m_force);
                if (!m_body.IsActive)
                    m_body.SetActive();
            }
            if (m_force != null && m_torque != Vector3.Zero)
            {
                m_body.AddBodyTorque(m_torque);
                if (!m_body.IsActive)
                    m_body.SetActive();
            }
        }

    #endregion

    }
}
